import ItemData from "../data/ItemData";
import LoadManager from "../manager/LoadManager";


// Learn TypeScript:
//  - [Chinese] http://docs.cocos.com/creator/manual/zh/scripting/typescript.html
//  - [English] http://www.cocos2d-x.org/docs/creator/manual/en/scripting/typescript.html
// Learn Attribute:
//  - [Chinese] http://docs.cocos.com/creator/manual/zh/scripting/reference/attributes.html
//  - [English] http://www.cocos2d-x.org/docs/creator/manual/en/scripting/reference/attributes.html
// Learn life-cycle callbacks:
//  - [Chinese] http://docs.cocos.com/creator/manual/zh/scripting/life-cycle-callbacks.html
//  - [English] http://www.cocos2d-x.org/docs/creator/manual/en/scripting/life-cycle-callbacks.html

const {ccclass, property} = cc._decorator;

@ccclass
export default class ItemBox extends cc.Component {

    @property(cc.Label)
    txt_num : cc.Label = null;
    @property(cc.Sprite)
     img_item :cc.Sprite =null;
    
    private _itemData:ItemData
    public set itemData(v : ItemData) {
        this._itemData = v;
        if(!v)
        {
            this.node.destroy();
            return;
        }
        this.txt_num.node.active = true;
        this.img_item.node.active = true;
        this.txt_num.string = this._itemData.num.toString();
        let id:string = String(this._itemData.itemId)
        let len:number = 4-id.length
        for (let index = 0; index < len; index++) {
            id = "0"+id
        }
        this.img_item.spriteFrame = LoadManager.instance.getImgResListByUrl("image/goods/g_"+id);
    }
    
    public get itemData() : ItemData {
        return this._itemData;
    }
    
    
   
}
